package com.TIEmulator;

import android.app.ListActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
import com.TIEmulator.FileIOLib.InternetFileIO;

public class DownloadManager extends ListActivity
  implements AssetHTMLView.HTMLViewerCb, View.OnClickListener, AdapterView.OnItemSelectedListener, CheckBoxifiedTextListAdapter.ItemClick
{
  public static final String START_BROWSER_PATH_ID = "2";
  private static String[][] down_url_fw_list;
  private static String[] items;
  private ArrayAdapter<String> mAdapterDownloadSpinner = null;
  private Button mDownloadButton = null;
  private Spinner mSpinner = null;
  private int selection_count = 0;
  private TIEmulatorSettings tiemu_setup;

  static
  {
    String[] arrayOfString1 = new String[5];
    arrayOfString1[0] = "TI Voyage 200";
    arrayOfString1[1] = "TI 92+";
    arrayOfString1[2] = "TI 92";
    arrayOfString1[3] = "TI 89 Titanium";
    arrayOfString1[4] = "TI 89";
    items = arrayOfString1;
    String[][] arrayOfString; = new String[5][];
    String[] arrayOfString2 = new String[3];
    arrayOfString2[0] = "TI Voyage 200 Firmware";
    arrayOfString2[1] = "http://education.ti.com/downloads/files/92_v200/";
    arrayOfString2[2] = "os.v2u";
    arrayOfString;[0] = arrayOfString2;
    String[] arrayOfString3 = new String[3];
    arrayOfString3[0] = "TI 92+ Firmware";
    arrayOfString3[1] = "http://education.ti.com/downloads/files/92_v200/";
    arrayOfString3[2] = "os.9xu";
    arrayOfString;[1] = arrayOfString3;
    String[] arrayOfString4 = new String[3];
    arrayOfString4[0] = "Sorry, NO TI 92 Firmware";
    arrayOfString4[1] = "na";
    arrayOfString4[2] = "na";
    arrayOfString;[2] = arrayOfString4;
    String[] arrayOfString5 = new String[3];
    arrayOfString5[0] = "TI 89t Firmware";
    arrayOfString5[1] = "http://education.ti.com/downloads/files/89/";
    arrayOfString5[2] = "TI89Titanium_OS.89u";
    arrayOfString;[3] = arrayOfString5;
    String[] arrayOfString6 = new String[3];
    arrayOfString6[0] = "TI 89 Firmware";
    arrayOfString6[1] = "http://education.ti.com/downloads/files/89/";
    arrayOfString6[2] = "os.89u";
    arrayOfString;[4] = arrayOfString6;
    down_url_fw_list = arrayOfString;;
  }

  private void setupView()
  {
    findViewById(2131296264).setOnClickListener(this);
    this.mDownloadButton = ((Button)findViewById(2131296263));
    this.mDownloadButton.setOnClickListener(this);
    findViewById(2131296273).setEnabled(false);
    this.mAdapterDownloadSpinner = new ArrayAdapter(this, 17367048);
    if (this.mAdapterDownloadSpinner == null)
      Log.e(super.toString(), "Error createing Download Spinner String adapter!");
    this.mSpinner = ((Spinner)findViewById(2131296273));
    this.mSpinner.setAdapter(this.mAdapterDownloadSpinner);
    this.mSpinner.setOnItemSelectedListener(this);
    ((TextView)findViewById(2131296274)).setText(this.tiemu_setup.getCurrDir());
  }

  public void onAccept()
  {
    CheckBoxifiedTextListAdapter localCheckBoxifiedTextListAdapter = new CheckBoxifiedTextListAdapter(this);
    for (int i = 0; ; ++i)
    {
      if (i >= items.length)
      {
        setListAdapter(localCheckBoxifiedTextListAdapter);
        setupView();
        return;
      }
      localCheckBoxifiedTextListAdapter.addItem(items[i]);
    }
  }

  public void onCheckBoxifiedTextItemClicked(int paramInt, boolean paramBoolean)
  {
    if (paramBoolean)
    {
      this.mAdapterDownloadSpinner.add(down_url_fw_list[paramInt][0]);
      if (this.selection_count == 0)
        this.mSpinner.setEnabled(true);
      this.selection_count = (1 + this.selection_count);
    }
    while (true)
    {
      return;
      this.selection_count -= 1;
      if (this.selection_count == 0)
        this.mSpinner.setEnabled(false);
      this.mAdapterDownloadSpinner.remove(down_url_fw_list[paramInt][0]);
    }
  }

  public void onClick(View paramView)
  {
    switch (paramView.getId())
    {
    default:
      Log.w(super.toString(), "unknown view has this in onclik listener: " + paramView.toString());
    case 2131296264:
      while (true)
      {
        label55: return;
        finish();
      }
    case 2131296263:
    }
    String str = (String)((TextView)this.mSpinner.getSelectedView()).getText();
    Log.i(super.toString(), "spinner selection: " + str + " down_url_fw_list length: " + down_url_fw_list.length);
    for (int i = 0; ; ++i)
    {
      if (i >= down_url_fw_list.length)
        Log.e(super.toString(), "no valid spinner string!!! ");
      if (!(str.equals(down_url_fw_list[i][0])))
        continue;
      InternetFileIO.startDownloadGUIThread(this, this.tiemu_setup.getCurrDir() + down_url_fw_list[i][2], down_url_fw_list[i][1] + down_url_fw_list[i][2]);
      break label55:
    }
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    this.tiemu_setup = new TIEmulatorSettings(this);
    setContentView(2130903042);
    if (!(LegalNotice.show(this)))
      return;
    onAccept();
  }

  public void onItemSelected(AdapterView<?> paramAdapterView, View paramView, int paramInt, long paramLong)
  {
    this.mDownloadButton.setEnabled(true);
    TextView localTextView = (TextView)paramView;
    Log.i(super.toString(), "onItemSelected id: " + paramLong + " text: " + localTextView.getText());
  }

  public void onNothingSelected(AdapterView<?> paramAdapterView)
  {
    this.mDownloadButton.setEnabled(false);
    Log.i(super.toString(), "onNothingSelected");
  }
}
